<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>DHTML Tree samples. dhtmlXTree - Add / Delete items</title>
	<meta name="KEYWORDS" content="dhtmlxtree, dhtml tree, javascript tree, javascript, DHTML, tree, tree menu, dynamical loading, xml, AJAX, API, cross-browser, checkbox, XHTML, compatible, treeview, navigation, menu, tree control, script, javascript navigation, web-site, dynamic, javascript tree menu, dhtml tree menu, dynamic tree, folder tree, item, node, asp, .net, jsp, cold fusion, custom tag, loading, widget, checkbox, drag, drop, drag and drop, component, html, scand">
<meta name="DESCRIPTION" content="Cross-browser DHTML tree menu with XML support and powerful API. This customizable DHTML JavaScript Tree Menu provides easy way to create efficient JavaScript navigation system.">

</head>
<style>
	body {font-size:12px}
	.{font-family:arial;font-size:12px}
	h1 {cursor:hand;font-size:16px;margin-left:10px;line-height:10px}
	xmp {color:green;font-size:12px;margin:0px;font-family:courier;background-color:#e6e6fa;padding:2px}
	.hdr{
		background-color:lightgrey;
		margin-bottom:10px;
		padding-left:10px;
	}
</style>
<body>
	<div class="hdr">DHTML JavaScript Tree samples</div>
	<h1>Add / Delete items</h1>
	<p>You can freely customize a tree view. This sample illustrates that the tree items can be easily 
	added/deleted dynamically through the graphical user interface.
	You can insert new item after the selected node or as its child. 
	This feature allows you to configure a DHTML tree menu effortlessly.</p>
	<link rel="STYLESHEET" type="text/css" href="../css/dhtmlXTree.css">
	<script  src="../js/dhtmlXCommon.js"></script>
	<script  src="../js/dhtmlXTree.js"></script>		
	<script>
		function fixImage(id){
			switch(tree.getLevel(id)){
			case 1:
			tree.setItemImage2(id,'books_close.gif','tombs.gif','tombs.gif');
				break;
			case 2:
			tree.setItemImage2(id,'book.gif','books_open.gif','books_close.gif');			
				break;
			case 3:
			tree.setItemImage2(id,'book.gif','books_open.gif','book.gif');			
				break;			
			default:
			tree.setItemImage2(id,'book_titel.gif','book_titel.gif','book_titel.gif');			
				break;
			}
		}
	</script>
	<table>
		<tr>
			<td valign="top">


				<div id="treeboxbox_tree" style="width:250; height:218;background-color:#f5f5f5;border :1px solid Silver;; overflow:auto;"></div>
			</td>
			<td rowspan="2" style="padding-left:25" valign="top">
			
			
			<a href="javascript:void(0);" onclick="var d=new Date(); tree.insertNewItem(tree.getSelectedItemId(),d.valueOf(),document.getElementById('ed1').value,0,0,0,0,'SELECT'); fixImage(d.valueOf());">Insert new child item</a> Item label <input type="text" value="New item" id="ed1"><br><br>
			
			<a href="javascript:void(0);" onclick="var d=new Date(); tree.insertNewNext(tree.getSelectedItemId(),d.valueOf(),document.getElementById('ed2').value,0,0,0,0,'SELECT'); fixImage(d.valueOf());">Insert new item next</a> Item label <input type="text" value="New item" id="ed2"><br><br>
			
			<a href="javascript:void(0);" onclick="tree.deleteItem(tree.getSelectedItemId(),true);">Delete item</a><br><br>
			

			
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
	</table>
	<hr>
			
<XMP>
<div id="treeboxbox_tree" style="width:200;height:200"></div>
<script>
	tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
		tree.setImagePath("../imgs/");
		tree.loadXML("tree.xml")
		
		tree.insertNewItem(0,100,"New Node 1",0,0,0,0,"SELECT");
		tree.insertNewNext(2,101,"New Node 2",0,0,0,0,"");
		tree.deleteItem("2");
</script>
</XMP>	
		<li>0s passed to the function for arguments 4-7 (function to call on select, images) mean use default values for them</li>
		<li>Last argument is a comma delimited string of following possible value (upper case only):</li>
			<li type="circle">SELECT - move selection to this node after inserting</li>
			<li type="circle">CALL - call function on select</li>
			<li type="circle">TOP - add node to the top position </li>
			<li type="circle">CHILD - node has children</li>
			<li type="circle">CHECKED - checkbox is checked (if exists)</li>
	<script>
			tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			tree.setImagePath("../imgs/");
			tree.loadXML("tree3.xml");

/*		
			
			tree.insertNewItem(1,100,"New Node 1",0,0,0,0,"SELECT");
			tree.insertNewNext(2,101,"New Node 2",0,0,0,0,"");
			tree.deleteItem("2");*/
	</script>
<br><br>
<p><a href="http://www.scbr.com/docs/products/dhtmlxTree/index.shtml" style="font-weight:bold;">Go to the dhtmlxTree main page</a> or <a href="javascript:self.close()">Close this page</a></p>
</body>
</html>
